package com.zs.blog.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Title: CreateOrUpdateTimeHandler
 * @Author zs
 * @Package com.zs.blog.handler
 * @Date 2024/11/26 22:49
 * @description: 创建时间/更新时间处理器
 */
@Component
public class CreateOrUpdateTimeHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
//        String TIME_FORMAT = "yyyy-MM-dd HH:mm";
//        DateTimeFormatter pattern = DateTimeFormatter.ofPattern(TIME_FORMAT);
//        String format = LocalDateTime.now().format(pattern);
//        LocalDateTime parse = LocalDateTime.parse(format, pattern);
        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
    }
}
